package com.itheima.case2.controller;

import com.itheima.case2.exception.BusinessException;
import com.itheima.case2.pojo.vo.Result;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class ProjectExceptionAdvice {

    /*
        专门处理BusinessException
     */
    @ExceptionHandler(BusinessException.class)
    public Result doBusinessException(BusinessException ex){
//        ex.printStackTrace();
        String message = ex.getMessage();
        return new Result(false,message);
    }

    @ExceptionHandler(Exception.class)
    public Result doException(Exception ex){
        ex.printStackTrace();
//        String message = ex.getMessage();

        return new Result(false,"服务器繁忙,请稍后重试");
    }
}
